let app = getApp()
var stylecss = require('../../utils/stylecss.js');
Component({
    properties: {
      scrollTop: {
        type: Number,
        observer: function(newVal, oldVal) {
          this.updatscroll()
        }
      },
      item: {
        type:Object
      }
      },
      data:{
      
      },


    lifetimes: {
        ready: function() {
          let that = this;
          const query = wx.createSelectorQuery().in(this)
          setTimeout(() => { 
             query.select('#'+this.data.item.id).boundingClientRect(res=>{
                  that.setData({
                    top:res.top
                  })
                  console.log(res.top);
                }).exec();
           }, 0);
         },
        attached: function () {
          var css=stylecss.css(this.data.item.id);
          var anima=stylecss.animated(this.data.item.id);
          this.setData({
            oldanima:anima,
            anima:anima
          })
          var tmpl_nav_icon=this.data.item.id+' .tmpl_nav_icon';
          var span=this.data.item.id+' span';
          var tmpl_nav_icon_css=stylecss.css(tmpl_nav_icon);
          var span_css=stylecss.css(span);
          this.setData({
            css:css,
            tmpl_nav_icon_css:tmpl_nav_icon_css,
            span_css:span_css
          })
          this.triggerEvent ('changeshare') 
       }
      },
    methods: {
      updatscroll:function(){
         var nowtop=this.data.scrollTop-this.data.top
         var oldanima=this.data.oldanima
         if(nowtop<=0){
          this.setData({
            anima:oldanima
          })
         }else{
           this.setData({
               anima:''
           })
         }
      },
      jumpurl:function(e){
        stylecss.jumpurl(this.data.item.list[e.currentTarget.dataset.index].link); 
      }
    }
});
